package com.jason.demo.servicehi.concurrent.con1;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @description description
 * @author zhouxinghuai
 * @date 2018-09-10
 */
public class RenentrantLockDemo {

    static Map<String, Object> map = new HashMap<>();
    static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    static Lock readLock = lock.readLock();
    static Lock writeLock = lock.writeLock();

    public void put(String key, Object value) {
        writeLock.lock();
        System.out.println("Start Put...");

        try {
            map.put(key, value);
        } finally {
            writeLock.unlock();
        }
    }

    public Object get(String key) {
        readLock.lock();
        System.out.println("Start Get...");
        try {
            return map.get(key);
        } finally {
            readLock.unlock();
        }
    }


}
